package com.longcai.controller.homepage;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.longcai.bean.ApiResult;
import com.longcai.entity.homepage.ClyjHeadlines;
import com.longcai.service.homepage.ClyjHeadlinesService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 * 平台头条 前端控制器
 * </p>
 *
 * @author LWK
 * @since 2019-03-20
 */
@Controller
@RequestMapping("/clyjHeadlines")
public class ClyjHeadlinesController {

    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private ClyjHeadlinesService bannerService;

    /**
     * description: 首页头条展示
     * author: LWK
     * time： 10点58分
     */
    @RequestMapping("/getHeadlinesList")
    @ResponseBody
    public ApiResult<List<ClyjHeadlines>> getHeadlinesList(@RequestBody JSONObject params) {
        ApiResult<List<ClyjHeadlines>> result = new ApiResult<List<ClyjHeadlines>>();
        try {
            //标识：0：首页头条；1：附近公告
            String flag = params.getString("flag");
            QueryWrapper<ClyjHeadlines> queryWrapper = new QueryWrapper<ClyjHeadlines>();
            queryWrapper.eq("flag", flag);
            queryWrapper.eq("status", "0");
            queryWrapper.orderByAsc("line_sort");
            result.success();
            result.setData(bannerService.selectList(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode("-1");
            result.fail("查询失败：" + e.getMessage());
        }
        return result;
    }

    /**
     * 新闻详情
     *
     * @param params
     * @return
     */
    @ResponseBody
    @RequestMapping("/getdetails")
    public ApiResult getdetails(@RequestBody JSONObject params) {
        //新闻id
        String id = params.getString("id");
        if (id == null || id.equals("")) {
            logger.error("id为空");
            return ApiResult.fail("查询失败");
        }
        return this.bannerService.getdetails(id);
    }


}

